package com.upb.webserver.dao.mapper;

import com.upb.webserver.dao.entity.TbManager;
import com.upb.webserver.dao.entity.TbManagerExample;
import com.upb.webserver.dao.entity.TbManagerWithAppID;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

public interface TbManagerMapper {

    @Select("select * from tb_manager where MD5(CONCAT(#{pid,jdbcType=VARCHAR},'##$$##',account)) in( select related_key from tb_security where appid=#{appid,jdbcType=VARCHAR})")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    TbManager getManagerByAppID(@Param("pid") String pid, @Param("appid") String appid);

    @Select({ "<script>", "select", TbManagerSqlProvider.ALL_COLUMN_FIELDS, "from tb_manager", "where role_id in", "<foreach collection='roleIdList' item='roleId' open='(' separator=',' close=')'>", "#{roleId}", "</foreach>", "</script>" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    List<TbManager> listByRoleIdList(@Param("roleIdList") List<Integer> roleIdList);

    @Select({ "select", TbManagerSqlProvider.ALL_COLUMN_FIELDS, "from tb_manager", "where email = #{email,jdbcType=VARCHAR}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    TbManager selectByEmail(@Param("email") String email);

    @Select({ "select", TbManagerSqlProvider.ALL_COLUMN_FIELDS, "from tb_manager", "where account = #{account,jdbcType=VARCHAR}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    TbManager selectByAccount(@Param("account") String account);

    @SelectProvider(type = TbManagerSqlProvider.class, method = "selectWithAppID")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "appid", property = "appid", jdbcType = JdbcType.VARCHAR), @Result(column = "security", property = "security", jdbcType = JdbcType.VARCHAR) })
    List<TbManagerWithAppID> selectWithAppID(TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbManagerSqlProvider.class, method = "countByExample")
    long countByExample(TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbManagerSqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @Delete({ "delete from tb_manager", "where id = #{id,jdbcType=INTEGER}" })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @Insert({ "insert into tb_manager (account, email, ", "password, login_fail_time, ", "status, role_id, ", "gmt_create, gmt_modified, ", "description)", "values (#{account,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, ", "#{password,jdbcType=VARCHAR}, #{loginFailTime,jdbcType=INTEGER}, ", "#{status,jdbcType=TINYINT}, #{roleId,jdbcType=INTEGER}, ", "#{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, ", "#{description,jdbcType=LONGVARCHAR})" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(TbManager record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbManagerSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertSelective(TbManager record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbManagerSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    List<TbManager> selectByExampleWithBLOBs(TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbManagerSqlProvider.class, method = "selectByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    List<TbManager> selectByExample(TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @Select({ "select", "id, account, email, password, login_fail_time, status, role_id, gmt_create, ", "gmt_modified, description", "from tb_manager", "where id = #{id,jdbcType=INTEGER}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    TbManager selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbManagerSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbManager record, @Param("example") TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbManagerSqlProvider.class, method = "updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") TbManager record, @Param("example") TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbManagerSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbManager record, @Param("example") TbManagerExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbManagerSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbManager record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @Update({ "update tb_manager", "set account = #{account,jdbcType=VARCHAR},", "email = #{email,jdbcType=VARCHAR},", "password = #{password,jdbcType=VARCHAR},", "login_fail_time = #{loginFailTime,jdbcType=INTEGER},", "status = #{status,jdbcType=TINYINT},", "role_id = #{roleId,jdbcType=INTEGER},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},", "description = #{description,jdbcType=LONGVARCHAR}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKeyWithBLOBs(TbManager record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @Update({ "update tb_manager", "set account = #{account,jdbcType=VARCHAR},", "email = #{email,jdbcType=VARCHAR},", "password = #{password,jdbcType=VARCHAR},", "login_fail_time = #{loginFailTime,jdbcType=INTEGER},", "status = #{status,jdbcType=TINYINT},", "role_id = #{roleId,jdbcType=INTEGER},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKey(TbManager record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert({ "<script>", "insert into tb_manager (account, ", "email, password, ", "login_fail_time, status, ", "role_id, gmt_create, ", "gmt_modified, description)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.account,jdbcType=VARCHAR}, ", "#{detail.email,jdbcType=VARCHAR}, #{detail.password,jdbcType=VARCHAR}, ", "#{detail.loginFailTime,jdbcType=INTEGER}, #{detail.status,jdbcType=TINYINT}, ", "#{detail.roleId,jdbcType=INTEGER}, #{detail.gmtCreate,jdbcType=TIMESTAMP}, ", "#{detail.gmtModified,jdbcType=TIMESTAMP}, #{detail.description,jdbcType=LONGVARCHAR})</foreach></script>" })
    int batchInsert(List<TbManager> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_manager
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbManagerSqlProvider.class, method = "getOneByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR), @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR), @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR), @Result(column = "login_fail_time", property = "loginFailTime", jdbcType = JdbcType.INTEGER), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR) })
    Optional<TbManager> getOneByExample(TbManagerExample example);
}
